function ListNode(val) {
    this.val = val;
    this.next = null;
};
/**
 * @param {ListNode} head
 * @return {number[]}
 */
var reversePrint = function(head) {

    let p = head;
    let n = 0;
    let arr = [];
    while (p != null) {
        n++;
        p = p.next;
    }
    // console.log(n)
    let q = head
    for (let i = 0; i < n; i++) {
        arr[n - 1 - i ] = q.val
        q = q.next
    }
    return arr
};
let head = new ListNode(1)
head.next = new ListNode(2)
head.next.next = new ListNode(3)
head.next.next.next = new ListNode(4)
head.next.next.next.next = new ListNode(5)
console.log(reversePrint(head))